Skip to content

Conversation

@arihant2math
Copy link
Collaborator

@arihant2math arihant2math commented Jan 5, 2026

No description provided.

@arihant2math arihant2math force-pushed the ptrace branch 4 times, most recently from 9412aa5 to 51e39b3 Compare January 5, 2026 23:54
arihant2math and others added 8 commits January 9, 2026 11:34
Fix current task double-borrow bug when exiting with a signal.
Make it such that when a ptrace event is hit:

 - The current regset is saved in the ptrace state.
 - The current task is put to sleep.
 - Arrange for a SIGCHLD to be set to the parent.
 - Notify any waiters with the appopriate signal.
handle `PTRACE_CONT` and `PTRACE_SYSCALL` operations.
Add option definitions `PTRACE_O_*` and change the ptrace state
depdening upon which options are set in the call.
When a new child stops due to a stoppable-signal after PTRACE_TRACEME,
send a SIGSTOP with a `PTRACE_EVENT_STOP`.
Add a function that allows an owned page to be atomically obtained from
a new process.
We currently union the UNMASKABLE_SIGNALS set with the new signal mask.
This does the complete opposite of what we wnat, we want to *remove*
those signals from the newly computed signal mask.

This patch removes the UNMASKABLE_SIGNALS set from any newly computed
signal mask.
Implement the `sys_process_vm_readv` syscall.
If a SIGKILL has been received, ensure all sleepy tasks are set to
runnable so that they can action the signal.
If a task has called one of `sys_exit` or `sys_exit_group`, don't follow
the standard syscall exit path. Since the task is dead and it will never
be rescheduled, there's no point in processing the result of sys_exit.
Add ptrace events for the exit family of syscalls.
If the calling process has no children and no pending exit events to
handle, return ECHILD instead of waiting forever.
@hexagonal-sun hexagonal-sun marked this pull request as ready for review January 11, 2026 22:31
@hexagonal-sun
Copy link
Owner

hexagonal-sun commented Jan 11, 2026

@arihant2math Okay, this now implements of enough ptrace logic to make strace work in moss! This also required the ability to get pages from another address space into the tracer for syscall arg decoding. I added the get_pages() function to do that and it's main userspace interface is implemented with sys_process_vm_readv.

I've also attached an strace binary to this comment so people have have a play.

strace.gz

[root@moss-machine /]# ./strace /bin/ls
./strace /bin/ls
execve("/bin/ls", ["/bin/ls"], 0x7fffffffff40 /* 3 vars */) = 0
brk(NULL)                               = 0x800000000000
faccessat(AT_FDCWD, "/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=20859, ...}) = 0
mmap(NULL, 20859, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fffff7fa000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/libcap.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0\267\0\1\0\0\0`}\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=67584, ...}) = 0
mmap(NULL, 196704, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_DENYWRITE, -1, 0) = 0x7fffff7c9000
mmap(0x7fffff7d0000, 131168, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0) = 0x7fffff7d0000
munmap(0x7fffff7c9000, 28672)           = 0
munmap(0x7fffff7f1000, 32864)           = 0
mprotect(0x7fffff7da000, 86016, PROT_NONE) = 0
mmap(0x7fffff7ef000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xf000) = 0x7fffff7ef000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0\267\0\1\0\0\0\340%\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1853856, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fffff7f8000
mmap(NULL, 1936736, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_DENYWRITE, -1, 0) = 0x7fffff5f7000
mmap(0x7fffff600000, 1871200, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0) = 0x7fffff600000
munmap(0x7fffff5f7000, 36864)           = 0
munmap(0x7fffff7c9000, 28000)           = 0
mprotect(0x7fffff7b0000, 53248, PROT_NONE) = 0
mmap(0x7fffff7bd000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bd000) = 0x7fffff7bd000
mmap(0x7fffff7c2000, 28000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fffff7c2000
close(3)                                = 0
set_tid_address(0x7fffff7f8f50)         = 4
set_robust_list(0x7fffff7f8f60, 24)     = 0
rseq(0x7fffff7f9640, 0x20, 0, 0xd428bc00) = -1 ENOSYS (Function not implemented)
mprotect(0x7fffff7bd000, 12288, PROT_READ) = 0
mprotect(0x7fffff7ef000, 4096, PROT_READ) = 0
mprotect(0x50000003e000, 8192, PROT_READ) = 0
mprotect(0x70000003e000, 8192, PROT_READ) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
getrandom("\x15\x5d\x7f\xdf\x82\x27\xf7\x30", 8, GRND_NONBLOCK) = 8
munmap(0x7fffff7fa000, 20859)           = 0
prctl(PR_CAPBSET_READ, CAP_MAC_OVERRIDE) = 1
prctl(PR_CAPBSET_READ, 0x30 /* CAP_??? */) = -1 EINVAL (Invalid argument)
prctl(PR_CAPBSET_READ, CAP_CHECKPOINT_RESTORE) = 1
prctl(PR_CAPBSET_READ, 0x2c /* CAP_??? */) = -1 EINVAL (Invalid argument)
prctl(PR_CAPBSET_READ, 0x2a /* CAP_??? */) = -1 EINVAL (Invalid argument)
prctl(PR_CAPBSET_READ, 0x29 /* CAP_??? */) = -1 EINVAL (Invalid argument)
brk(NULL)                               = 0x800000000000
brk(0x800000021000)                     = 0x800000021000
ioctl(1, TCGETS2, 0x7ffffffffc48)       = -1 ENOTTY (Inappropriate ioctl for device)
openat(AT_FDCWD, ".", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
fstat(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
getdents64(3, 0x800000005000 /* 26 entries */, 32768) = 672
getdents64(3, 0x800000005000 /* 0 entries */, 32768) = 0
close(3)                                = 0
fstat(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(0, 0), ...}) = 0
ioctl(1, TCGETS2, 0x7fffffffd678)       = -1 ENOTTY (Inappropriate ioctl for device)
write(1, "a.out\nbash\nbin\nboot\nbusybox\ndev\n"..., 126a.out
bash
bin
boot
busybox
dev
etc
home
lib
lost+found
mnt
opt
proc
root
run
sbin
srv
strace
sys
test.c
tmp
usertest
usr
var
) = 126
close(1)                                = 0
close(2)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++
[root@moss-machine /]#

Copy link
Collaborator Author

@arihant2math arihant2math left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@arihant2math arihant2math merged commit 64bc004 into hexagonal-sun:master Jan 12, 2026
4 checks passed
@arihant2math arihant2math deleted the ptrace branch January 12, 2026 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants